package pri.black.dogview.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import pri.black.dogview.domain.Admin;

import java.util.Collection;
import java.util.List;

public class AdminDetails implements UserDetails {

    Admin admin = null;

    public AdminDetails(Admin admin) {
        this.admin = admin;
    }

    @Override
    public boolean isEnabled() {
        return admin.getState() == 1;
    }

    @Override
    public String getUsername() {
        return admin.getUsername();
    }

    @Override
    public String getPassword() {
        return admin.getPassword();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of(new SimpleGrantedAuthority("admin"));
    }

    public Admin getAdmin() {
        return admin;
    }
}
